from odoo import fields, models, api
from odoo.exceptions import UserError
from random import randint


class RPWebArticleTag(models.Model):
    _name = 'rp.web.article.tag'
    _description = "文章标签"
    _rec_name = "name"
    _sql_constraints = [('unique_name', 'UNIQUE(name)', '名称重复')]

    def _get_default_color(self):
        return randint(1, 11)

    name = fields.Char(string='名称', index=True, copy=False, required=True, translate=True)
    desc = fields.Text(string='描述')

    color = fields.Integer(string='颜色', default=_get_default_color)

    active = fields.Boolean(string='有效', default=True)
